﻿import com.dmotiko.zonaoutlet.*
import com.dmotiko.general.*
import com.dmotiko.util.*;
import mx.utils.Delegate;
import mx.transitions.*;
import mx.transitions.easing.*;

class ZOOutletTemplate
extends BaseClip {
	
	// FLA VARS
	private var photoViewer:ZOPhotoOutletViewer;
	private var txtName:TextField;
	private var txtDescription:TextField;
	private var mcAddress:ZOAddressOutlet;
	private var mcIcon:MovieLoaderClip;
	private var mcIconSep:MovieClip;
	private var bcPromo:ButtonClip;
	
	private var descriptionTween:MovieClip;
		
	function ZOOutletTemplate() {
		super();
	}
	
	private function initClip():Void {
		txtName.text = "";
		txtDescription.text = "";
		txtDescription.autoSize = "left";
	}
	
	private function refreshData():Void {
		if ( data.logoSrc ) {
			txtName._visible = false;
		} else {
			txtName.text = data.name;
		}
		txtDescription.text = data.description;
	}
	
	public function childLoaded( evnt ):Void {
		switch( evnt.target ) {
			case mcAddress:
			mcAddress.setData( data.addresses[0] );
			break;
			
			case photoViewer:
			photoViewer.setData( data.photos );
			break;
			
			case mcIcon:
			if ( data.logoSrc ) {
				mcIcon.loadContent( data.logoSrc );
				mcIcon.addEventListener( MovieLoaderClip.CLIP_LOADED, Delegate.create( this, layoutDescription ) );
			}
			break;
			
			case bcPromo:
			bcPromo.addEventListener( BaseClipEvent.CHANGED, Delegate.create(this, btn_promo));
			break;
			
		}
		
	}
	
	private function btn_promo(evnt):Void {
		ZOSite.getApp().setSection( ZOSite.PROMOCIONES );
	}
	
	private function layoutDescription( evnt ) {
		registerTween( "iconFade", new Tween( evnt.clip, "_alpha", Regular.easeOut, 0, 100, 0.5, true) );
		if ( mcIcon._height > 50 ) mcIconSep._y = mcIcon._y + mcIcon._height + 2;
		else mcIconSep._y = mcIcon._y + 52;
		
		mcIcon._y = ( (mcIconSep._y) - (mcIcon._height) ) / 2;
		
		txtDescription._y = mcIconSep._y + mcIconSep._height + 2;
	}
	
}